package org.hhchat.leetcode.string;

public class code680_easy {

    static class Solution {
        public boolean validPalindrome(String s) {
            return check(s, false);
        }

        public boolean check(String s, boolean flag) {
            int p = 0, q = s.length() - 1;
            while (p < q) {
                if (p < q && s.charAt(p) == s.charAt(q)) {
                    p++;
                    q--;
                } else if (p < q && s.charAt(p) != s.charAt(q) && !flag) {
                    StringBuilder stringBuilder = new StringBuilder(s);
                    stringBuilder.deleteCharAt(p);
                    if (check(stringBuilder.toString(),true)) {
                        return true;
                    }
                    stringBuilder = new StringBuilder(s);
                    stringBuilder.deleteCharAt(q);
                    if (check(stringBuilder.toString(), true)) {
                        return true;
                    }
                    return false;
                }
                return false;
            }
            return true;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.validPalindrome("aba"));
    }

}
